﻿using StoreSQLSugar.Models;
using StoreSQLSugar.Models.ViewModel;
using System;
using System.Collections.Generic;

namespace StoreSQLSugar.Forms.ProductFrm
{
    public partial class ProductListFrm : BaseListFrm<Product, VProduct, ProductAddEditFrm>
    {
        public ProductListFrm()
        {
            InitializeComponent();
            Load += ProductListFrm_Load;
        }

        private void ProductListFrm_Load(object sender, System.EventArgs e)
        {
            cbbSearchCondition.Items.Insert(0, "产品名称");
            cbbSearchCondition.Items.Insert(0, "产品编码");
            cbbSearchCondition.SelectedIndex = 0;
            ucPager1.Page = 1;
        }

        public override void UcPager1_PageChanged(object sender, EventArgs e)
        {
            var exp = BuildCondition();

            if (!cbbSearchCondition.SelectedItem.ToString().Contains("时间"))
            {
                exp.OrIF(!string.IsNullOrWhiteSpace(TxtCondition.Text), ut =>
                   ut.ProductNo.Contains(TxtCondition.Text) ||
                   ut.ProductName.Contains(TxtCondition.Text)
                   );
            }

            Search(exp, "ProductId desc");

            List<dynamic> headerColumns = new List<dynamic>() {
                new { Name="ProductId", HeaderText="产品主键"},
                new { Name="ProductNo", HeaderText="产品编码"},
                new { Name="ProductName", HeaderText="产品名称"},
                new { Name="MinTemperature", HeaderText="最小温度"},
                new { Name="MaxTemperature", HeaderText="最大温度"}
            };
            List<dynamic> hiddenColumns = new List<dynamic>();
            List<dynamic> formatColumns = new List<dynamic>();
            SetColumn(headerColumns, hiddenColumns, formatColumns);
        }
    }
}
